<template>
	<view class="page_wrapper">
		<view class="loginimg">
			<image class="lgimg" src="../../static/nimg/logo.png" mode=""></image>
			<image class="upimg" src="../../static/nimg/ddup.png" mode=""></image>
		</view>
		<view class="loginbtn">
			<button class="btn" @click="handleLogin()">微信一键登录</button>
		</view>
		<image src="../../static/nimg/bg.png" class="page_bg_img" mode=""></image>
	</view>
</template>

<script>
	import {
		request
	} from '@/utils/request.js'
	import {
		storageData
	} from '@/utils/storageData.js'
	export default {
		data() {
			return {
				
			};
		},
		methods:{
			handleLogin(){
				uni.showLoading({
					title:'登录中...'
				})
				wx.getUserInfo({
					success(res) {
						wx.login({
							success(e) {
								request.postJson('/account/wxMinProgramLogin', {
									code: e.code,
									nickName: res.userInfo.nickName,
									avatarUrl: res.userInfo.avatarUrl
								}).then(lgres => {
									storageData.saveLoginUser({
										accessToken: lgres.result
									})
									request.get('/account/info').then(info => {
										if (info.result) {
											let obj = Object.assign({
												accessToken: lgres.result
											}, info.result)
											storageData.saveLoginUser(obj)
											uni.redirectTo({
												url:'/pages/index/index'
											})
										} else {
											uni.showToast({
												title: '登录失败',
												icon: 'none'
											})
										}
									})
								})
							}
						})
					}
				})
			},
			
		},
		onShareAppMessage(res) {
			// const userInfo = storageData.getLoginUser()
			if (res.from === 'button') {
				// 来自页面内分享按钮
				console.log(res.target);
			}
			return {
				title: '小奕口算：学习好帮手',
				path: '/pages/index/index',
				mpId: 'wxcbbe1a868c5c3c3c', //此处配置微信小程序的AppId
				imageUrl: 'https://www.hzif.cn/mathematics-attach/share.png'
			}
		},
		onShareTimeline(res) {
			// const userInfo = storageData.getLoginUser()
			return {
				title: '小奕口算：学习好帮手',
				path: '/pages/index/index',
				mpId: 'wxcbbe1a868c5c3c3c', //此处配置微信小程序的AppId
				imageUrl: 'https://www.hzif.cn/mathematics-attach/share.png'
			}
		},
		// 收藏
		onAddToFavorites(res) {
			return {
				title: '小奕口算：学习好帮手',
				path: '/pages/index/index',
				mpId: 'wxcbbe1a868c5c3c3c', //此处配置微信小程序的AppId
				imageUrl: 'https://www.hzif.cn/mathematics-attach/share.png'
			}
		}
	}
</script>

<style lang="scss">
.loginbtn{
	position: relative;
	z-index: 4;
	left: 0;
	width: 100%;
	right: 0;
	top: 40%;
	border-radius: 50rpx;
	margin:0 auto;
	.btn{
		background-color: #2E996C;
		color:white;
		font-size: 32rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border: none;
		border-radius: 50rpx;
		width: 90%;
		height: 98rpx;
	}
	.btn::after{
		border: none;
	}
}
.loginimg{
	top: 25%;
	position: relative;
	z-index: 4;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}
.lgimg{
	width:305rpx;
	height: 305rpx;
}
.upimg{
	height: 118rpx;
	width: 324rpx;
}
</style>
